package com.yaojianfeng.ollama.controller;

import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.ai.ollama.api.OllamaOptions;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ollama")
public class OllamaChatController {
    private final OllamaChatModel chatModel;

    public OllamaChatController(OllamaChatModel chatModel) {
        this.chatModel = chatModel;
    }

    @RequestMapping("/chat/{msg}")
    public String chat(@PathVariable String msg) {
        ChatResponse response = chatModel.call(new Prompt(msg, OllamaOptions.builder().withTemperature(0.4).build()));
        return response.getResult().getOutput().getContent();
    }
}

